<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
  <!ENTITY dc "http://purl.org/dc/elements/1.1/">
  <!ENTITY dcterms "http://purl.org/dc/terms/">
  <!ENTITY foaf "http://xmlns.com/foaf/0.1/">
  <!ENTITY a "http://xmlns.heustics.org/schema/myelin/0.1/">
  <!ENTITY m "http://xmlns.heustics.org/ontology/myelin/0.1/">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exslt="http://exslt.org/common"
  xmlns:l="http://xmlns.heustics.org/schema/i18n/0.1/"
  xmlns:a="&a;"
  xmlns:o="&a;grouping-container#"
  exclude-result-prefixes="xsl exslt l a o"
>
  <xsl:variable name="o:theme" select="a:get-l10n('&a;grouping-container#theme')"/>
  <xsl:variable name="o:l10n" select="a:get-l10n('&a;grouping-container')"/>  
  <xsl:variable name="o:container-l10n" select="$o:l10n/l:context[@name='container']/*"/>
  
  <xsl:template match="a:grouping[@role='container']"/>
    
  <xsl:template match="a:grouping" mode="a:container-header" name="a:container-header">
    <xsl:param name="grouping-url" select="a:format-url(a:public-url(@uri))"/>
    <xsl:param name="label" select="string(@title)"/>
    <div class="label">
      <xsl:if test="$label">
        <xsl:choose>
          <xsl:when test="@permitted-action">
            <a href="{$grouping-url}" title="{@tag}">
              <xsl:value-of select="$label"/>          
            </a>   
          </xsl:when>
          <xsl:otherwise>
            <span>
              <xsl:value-of select="$label"/>
            </span>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
      <div class="spacer"/> 
    </div>
  </xsl:template>
  
   <xsl:template match="a:grouping" mode="a:container-description" name="a:container-description">
    <xsl:if test="@description">
      <div class="description">
        <span><xsl:value-of select="@description"/></span>
        <div class="spacer"/>
      </div>
    </xsl:if>
  </xsl:template>
  
  <xsl:template match='a:grouping[@count and @role="container"]' name="a:container">
    <xsl:param name="config" select="/*/a:config"/>
    <xsl:param name="account" select="/*/a:account"/>
    <div class='container'>      
      <xsl:variable name="grouping-url" select="a:format-url(a:public-url(@uri))"/> 
      <div class="container_header">
        <xsl:apply-templates select="." mode="a:container-header">
          <xsl:with-param name="grouping-url" select="$grouping-url"/>
          <xsl:with-param name="config" select="$config"/>
          <xsl:with-param name="account" select="$account"/>
        </xsl:apply-templates>
        <div class="spacer"/>
      </div>      
      <div class="container_description">
        <xsl:apply-templates select="." mode="a:container-description">
          <xsl:with-param name="config" select="$config"/>
          <xsl:with-param name="account" select="$account"/>
        </xsl:apply-templates>
        <div class="spacer"/>
      </div>      
      <div class='container_nodes'>
        <ul>            
          <xsl:for-each select="*">
            <li>     
              <xsl:call-template name="a:even-odd-class-attr"/>
              <xsl:apply-templates select="." mode="a:container-node">
                <xsl:with-param name="l10n" select="$o:container-l10n"/>
                <xsl:with-param name="config" select="$config"/>
                <xsl:with-param name="account" select="$account"/>
                <xsl:with-param name="theme" select="$o:theme/l:context[@name='container-node']/*"/>
              </xsl:apply-templates>  
              <div class="spacer"/> 
            </li>
          </xsl:for-each> 
        </ul>        
        <div class="spacer"/>       
      </div>  
      <!-- there will always be 1 or more nodes -->
      <xsl:if test="@more">
        <div class="container_more">
          <a href='{$grouping-url}'>
            <xsl:value-of select="$o:container-l10n[@key='more']"/>
          </a>
          <div class="spacer"/>
        </div>    
      </xsl:if>      
      <div class="spacer"/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:node" mode="a:container-node" name="a:container-node">    
    <xsl:param name="l10n" select="$o:container-l10n"/> 
    <!--xsl:param name="theme" select="$o:theme/l:context[@name='container-node']/*"/ -->
    <!-- xsl:variable name="edit" select="a:node-acls/a:acl[@action='edit']"/ -->
    <div class="actions-and-title">
            
      <div class='title'>
        <a href="{a:format-url(a:public-url(@uri))}" 
          title="{@tag}">
          <xsl:value-of select='@title'/>
        </a>
        <div class='spacer'/>   
      </div>   
      
      <div class='spacer'/>
    </div>
    
    <!-- already displayed as link title -->
    <!-- xsl:if test="$edit">
      <div class='metadata tag'>
        <span>
          <xsl:value-of select='a:tag'/>
        </span>
        <div class='spacer'/>   
      </div>
    </xsl:if  -->      
    
    <!-- xsl:choose>
      <xsl:when test="@modified">
        <div class='metadata modified'>
          <span>
            <xsl:value-of select='substring-before(a:format-date(@modified),"T")'/>
          </span>
          <div class='spacer'/>   
        </div>
        <xsl:variable name="modifier" select="a:last-modifier"/>
        <xsl:if test="$modifier">
          <div class='metadata agent last-modifier'>        
            <xsl:apply-templates select="$modifier" mode="a:container-node-author">
              <xsl:with-param name="l10n" select="$l10n"/>
            </xsl:apply-templates>
            <div class='spacer'/>   
          </div>      
        </xsl:if> 
      </xsl:when>
      <xsl:when test="@created">
        <div class='metadata created'>
          <span>
            <xsl:value-of select='substring-before(a:format-date(@created),"T")'/>
          </span>
          <div class='spacer'/>   
        </div>     
        <xsl:variable name="creator" select="a:creator"/>  
        <xsl:if test="$creator">
          <div class='metadata agent creator'>        
            <xsl:apply-templates select="$creator" mode="a:container-node-author">
              <xsl:with-param name="l10n" select="$l10n"/>
            </xsl:apply-templates>
            <div class='spacer'/>   
          </div>      
        </xsl:if>          
      </xsl:when>
    </xsl:choose -->  
    
    <div class="description">
      <span><xsl:value-of select="a:description"/></span>
      <div class="spacer"/>
    </div>
    
  </xsl:template> 
  
  <xsl:template match="a:*[@node-id]" mode="a:container-node-author">
    <xsl:param name="key" select="local-name()"/>
    <xsl:param name="l10n" select="$o:container-l10n"/>
    <span class="author-wo-profile">
      <xsl:choose>
        <xsl:when test="@nick">
          <xsl:value-of select='@nick'/>
        </xsl:when>
        <xsl:when test="@name">
          <xsl:value-of select='@name'/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select='$l10n[@key="unknown-user"]'/>
        </xsl:otherwise>
      </xsl:choose>            
    </span>                   
  </xsl:template> 
  
  <xsl:template match="a:*[a:profile]" mode="a:container-node-author">
    <xsl:param name="key" select="local-name()"/>
    <xsl:param name="l10n" select="$o:container-l10n"/>
    <a href="{a:format-url(a:public-url(a:profile/@uri))}" 
      title="{$l10n[@key=$key]}">
      <xsl:choose>
        <xsl:when test="@nick">
          <xsl:value-of select='@nick'/>
        </xsl:when>
        <xsl:when test="@name">
          <xsl:value-of select='@name'/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select='$l10n[@key="unknown-user"]'/>
        </xsl:otherwise>
      </xsl:choose>            
    </a>                   
  </xsl:template>
      
</xsl:stylesheet>

